from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.versioning import URLPathVersioning
from hlq import models
import uuid

class LoginView(APIView):
    """用户登录视图"""
    versioning_class = [URLPathVersioning, ]

    def post(self, request, *args, **kwargs):
        user_obj = models.UserInfo.objects.filter(**request.data).first()
        if not user_obj:
            return Response("登录失败")
        random_string = str(uuid.uuid4())
        user_obj.token = random_string
        user_obj.save()
        return Response(random_string)
